package com.example.order.controller;

import com.example.common.api.ResultUtil;
import com.example.common.validator.Insert;
import com.example.order.model.vo.OrderVO;
import com.example.order.model.vo.PreOrderVO;
import com.example.order.service.IOrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/api/order")
@Slf4j
@Validated
public class OrderController {

    @Resource
    private IOrderService orderService;

    // 确认订单
    @RequestMapping(value = "/confirm_order", method = RequestMethod.POST)
    @ResponseBody
    public Mono<ResultUtil> confirmOrder(@RequestBody PreOrderVO preOrderVO){
        return orderService.confirmOrder(preOrderVO);
    }

    //创建订单
    @RequestMapping(value = "/create_order", method = RequestMethod.POST)
    @ResponseBody
    public Mono<ResultUtil> createOrder(@RequestBody @Validated(Insert.class)OrderVO orderVO) throws ExecutionException, InterruptedException {
        return orderService.createOrder(orderVO);
    }

}
